﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS_BEGINNER_TO_PROFICIENT.DesignPatterns.StructuralMode.AdapterPattern
{
    public interface MediaPlayer
    {
        void Play(string audioType, string fileName);
    }

    public interface AdvancedMediaplayer
    {
        void PlayVlc(string fileName);
        void PlayMp4(string fileName);
    }

    public class VlcPlayer : AdvancedMediaplayer
    {
        public void PlayMp4(string fileName) { }

        public void PlayVlc(string fileName) => Console.WriteLine("Playing vlc file, Name: " + fileName);
    }

    public class Mp4Player : AdvancedMediaplayer
    {
        public void PlayMp4(string fileName) => Console.WriteLine("Playing mp4 file, Name: " + fileName);

        public void PlayVlc(string fileName) { }
    }

    public class MediaAdapter : MediaPlayer
    {
        AdvancedMediaplayer advancedMediaplayer;

        public MediaAdapter(string audioType)
        {
            if (audioType.Equals("vlc", StringComparison.OrdinalIgnoreCase)) advancedMediaplayer = new VlcPlayer();
            else if (audioType.Equals("mp4", StringComparison.OrdinalIgnoreCase)) advancedMediaplayer = new Mp4Player();
        }

        public void Play(string audioType, string fileName)
        {
            if (audioType.Equals("vlc", StringComparison.OrdinalIgnoreCase)) advancedMediaplayer.PlayVlc(fileName);
            else if (audioType.Equals("mp4", StringComparison.OrdinalIgnoreCase)) advancedMediaplayer.PlayMp4(fileName);
        }
    }

    public class AudioPlayer : MediaPlayer
    {
        MediaAdapter mediaAdapter;

        public void Play(string audioType, string fileName)
        {
            if (audioType.Equals("mp3", StringComparison.OrdinalIgnoreCase)) Console.WriteLine("Playing mp3 file, Name: " + fileName);
            else if (audioType.Equals("vlc", StringComparison.OrdinalIgnoreCase) || audioType.Equals("mp4", StringComparison.OrdinalIgnoreCase))
            {
                mediaAdapter = new MediaAdapter(audioType);
                mediaAdapter.Play(audioType, fileName);
            }
            else Console.WriteLine("Invalid media. " + audioType + " format not supported");
        }
    }

    public class AdapterPatternDemo
    {
        public static void Execute()
        {
            AudioPlayer audioPlayer = new AudioPlayer();
            audioPlayer.Play("vlc", "Vlog.vlc");
        }
    }
}
